<template>
	<view class="container">
		<navView navTitle="新增客户" backgroundColor="#008efe" titleColor="#fff" :isBack="true"></navView>
		<!-- 头部区域 -->
		<view class="header">
			<view class="select-row">
				<uni-datetime-picker class="date-picker" type="daterange" v-model="dateRange" @change="handleDateChange"
					:clear-icon="false" />
			</view>
			<!-- 中间数字显示 -->
			<view class="count-box">
				<text class="count">{{ totalCount }}</text>
			</view>
		</view>

		<!-- 内容区域 -->
		<view class="content">
			<view class="user-card" v-for="(user, index) in userList" :key="index">
				<view class="user-info">
					<image class="avatar" src="https://hfd.bjlzkj.com/static/user/ava.png" />
					<view class="user-details">
						<text class="username">{{ user.name }}</text>
						<view class="status">
							<text>状态: </text>
							<text class="status-color">{{ user.follow }}</text>
						</view>
					</view>
				</view>
				<text class="company">地址: {{ user.address }}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			const now = new Date()
			const firstDay = new Date(now.getFullYear(), now.getMonth(), 1)
			const lastDay = new Date(now.getFullYear(), now.getMonth() + 1, 0)
			return {
				currentMonth: '一月份', // 当前月份
				currentYear: '2023年', // 当前年份
				totalCount: 15, // 总数
				userList: [],
				dateRange: [
					`${firstDay.getFullYear()}-${(firstDay.getMonth() + 1).toString().padStart(2, '0')}-01`,
					`${lastDay.getFullYear()}-${(lastDay.getMonth() + 1).toString().padStart(2, '0')}-${lastDay.getDate().toString().padStart(2, '0')}`
				],
			};
		},
		onShow() {
			this.getStaffStatistics()
		},
		methods: {
			// 处理月份选择器变化
			handleMonthChange(e) {
				const selectedMonth = e.detail.value;
				this.currentMonth = selectedMonth;
			},
			// 处理年份选择器变化
			handleYearChange(e) {
				const selectedYear = e.detail.value;
				this.currentYear = selectedYear;
			},
			// 获取数据简报列表
			getStaffStatistics() {
				this.$request('/addons/qingdong/staff/getStaffStatistics', 'GET',{
					times: this.dateRange.join(',')
				}).then(res => {
					this.totalCount = res.data.customer.count
					this.userList = res.data.customer.list
				})
			}
		},
	};
</script>

<style scoped lang="scss">
	.select-row {
		.date-picker {
			width: 100%;

			::v-deep .uni-date-editor {
				width: 100%;
				height: 70rpx;
			}
		}
	}
	/* 通用样式 */
	.container {
		display: flex;
		flex-direction: column;
		height: 100vh;
		background-color: #f5f5f5;
	}

	/* 头部区域 */
	.header {
		background-color: #008efe;
		color: #ffffff;
		padding: 20rpx 30rpx;
		position: relative;
		padding-bottom: 80rpx;
	}

	::v-deep .uni-stat-box {
		border-radius: 20rpx;
	}

	::v-deep .uni-select {
		border: 0;
		height: 28px;
	}

	.select-row {
		display: flex;
		justify-content: center;

		.uni-data-select {
			width: 200rpx;
			margin: 0 20rpx;
		}
	}

	.select-box {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.down-arrow {
		width: 20rpx;
		height: 20rpx;
		margin-left: 10rpx;
	}

	.count-box {
		text-align: center;
		margin-top: 20rpx;
		font-size: 60rpx;
		font-weight: bold;
		color: #ffffff;
	}

	/* 内容区域 */
	.content {
		flex: 1;
		padding: 20rpx;
	}

	.user-card:first-child {
		margin-top: -60rpx;
		position: relative;
	}

	.user-card {
		background-color: #ffffff;
		border-radius: 10rpx;
		margin-bottom: 20rpx;
		padding: 20rpx;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
	}

	.user-info {
		display: flex;
		align-items: center;
		margin-bottom: 10rpx;
	}

	.avatar {
		width: 50rpx;
		height: 50rpx;
		border-radius: 50%;
		margin-right: 20rpx;
	}

	.user-details {
		flex: 1;
	}

	.username {
		font-size: 30rpx;
		font-weight: bold;
	}

	.status {
		font-size: 24rpx;
		margin-top: 5rpx;
	}

	.status-color {
		color: #2484ff;
	}

	.company {
		font-size: 24rpx;
		margin-top: 10rpx;
		color: #666666;
	}
</style>